import 'package:get/get.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:video_setting/pages/constant/app_constant.dart';

class ViewSettingController extends GetxController {
  var pictureSetting = 0;
  var videoSetting = 0;
  var connectStateStr = '';
  SharedPreferences? sharedPreferences;

  @override
  void onReady() async {
    sharedPreferences = await SharedPreferences.getInstance();
    pictureSetting = sharedPreferences?.getInt(AppConstant.PICTURE_KEY) ?? 0;
    videoSetting = sharedPreferences?.getInt(AppConstant.VIDEO_KEY) ?? 0;

    super.onReady();
    update();
  }

  void pictureTimeSetting(int time) {
    pictureSetting = time;
    if (sharedPreferences != null) {
      sharedPreferences?.setInt(AppConstant.PICTURE_KEY, time);
    }
    update();
  }

  void videoTimeSetting(int time) {
    videoSetting = time;
    if (sharedPreferences != null) {
      sharedPreferences?.setInt(AppConstant.VIDEO_KEY, time);
    }
    update();
  }
}
